<?php

class Response
{
    /**
     * @var string
     */
    public $content = '';

    /**
     * view scripts
     * @return scripts
     */
    public $_script = '';

    /**
     * data array
     * @var array
     */
    public $data = array();

    /**
     * Main Request Object
     * @var Object
     */
    public $object = null;

    /**
     * preset script
     */
    public function setScript($script)
    {
        $this -> _script = $script;
        return $this;
    }

    /**
     * assign based function
     */
    public function assign($name, $value = null)
    {
        if (is_string($name))
        {
            $this -> data[$name] = $value;
        }
        else
        {
            foreach ($name as $key => $value)
            {
                $this -> data[$key] = $value;
            }
        }
        return $this;
    }

    /**
     * path magic call to any thing of data to views scripts.
     */
    public function execute($format = null)
    {
        if ($format == 'json')
        {
            $this -> content = json_encode($format);
        }
        else
        {
            $this -> content = View::getInstance() -> render($this -> data, $this -> _script, 1);
        }
        unset($this -> data);
        return $this;
    }

    public function __set($name, $value)
    {
        $this -> data[$name] = $value;
        return $this;
    }

    public function __get($name)
    {
        return isset($this -> data[$name]) ? $this -> data[$name] : null;
    }

}
